<template>
	<view>
		<view v-if="user==undefined||user==''">
			<login @loginBack="loginOk"></login>
		</view>
		<view v-else>
			<myDetail :points="points" :myselfInfo="jieshao" @lagoutBack="lagoutBack"></myDetail>
		</view>
	</view>
</template>

<script>
	import myDetail from '../../components/my/my-detail.vue'
	export default {
		components:{
			myDetail
		},
		mounted() {
			console.log('mounted-----');
			this.user = uni.getStorageSync('userKey');
			this.jieshao = uni.getStorageSync('jieshao');
			if(!this.jieshao){
				this.getJieShao();
			}
			if(this.user){
				this.getPoints();
			}
		},
		onShow() {
			console.log('onShow-----');
			this.user = uni.getStorageSync('userKey');
			this.jieshao = uni.getStorageSync('jieshao');
			if(!this.jieshao){
				this.getJieShao();
			}
		    if(this.user){
				this.getPoints();
			}
		},
		onLoad(options) {
			console.log('options---options',options);
			console.log('onLoad----');
			this.user = uni.getStorageSync('userKey');
			this.jieshao = uni.getStorageSync('jieshao');
		},
		data() {
			return {
				user:undefined,
				points:'',
				jieshao:'点击这里，填写简介...',
				myselfInfo:''
			};
		},
		methods:{
			loginOk(){
				this.user = uni.getStorageSync('userKey');
				this.jieshao = uni.getStorageSync('jieshao');
				if(!this.jieshao){
					this.getJieShao();
				}
				if(this.user){
					this.getPoints();
				}
			},
			update(){
				console.log('work_from.sss',this.myselfInfo);
				this.jieshao = this.myselfInfo;
				this.updateData();
			},
			lagoutBack(){
				console.log('hahahahah')
				this.user = uni.getStorageSync('userKey');
			},
			
			async updateData() {
				const {data:res} =await uni.$http.post('/sys_user/update/by_account',{workFrom:this.myselfInfo});
				if(res){
					uni.setStorageSync('jieshao',this.jieshao);
				}
			 },
			
			async getPoints() {
				const {data:res} =await uni.$http.post('/sys_points/get_points');
				this.points = res.data;
			 },
			 async getJieShao() {
			 	const {data:res} =await uni.$http.get('/sys_user/info/baby');
				if(res.data.workFrom!=undefined&&res.data.workFrom!=''){
					this.jieshao = res.data.workFrom;
					uni.setStorageSync('jieshao',this.jieshao);
				}
			  },
			 
			
		}
	}
</script>

<style lang="scss">

</style>
